#include "comm.hpp"
 
 int main(){
    key_t k = getKey();
    int shmid = getShm(k,gsize);
    char* addr  = (char*)shmat(shmid,nullptr,0);

    
    int wfd = my_open(fifoname.c_str(),O_WRONLY);

    int rfd = my_open(fifoname1.c_str(),O_RDONLY);

    while(true){
        int i=0;
        while(true){
            char ch;
            ch = getchar();
            if(ch=='\n')break;
            addr[i]=ch;
            i++;
        }
        addr[i]='\0';

        char arr[]="client写完了，你可以开始读取共享内存了\n";
        write(wfd,arr,sizeof(arr));

        char buff[1024]={0};
        ssize_t n = read(rfd,buff,sizeof(buff)-1);
         if(n>0){
            //buffer[n]=0;
            printf("%s",buff);
            fflush(stdout);
            
        }else{
            cout<<errno<<":"<<strerror(errno)<<endl;
            break;
        }
    }
    
    
    close(wfd);
    close(rfd);
    shmdt(addr);
    return 0;
 }